package com.central.consume.controller;

import com.central.consume.model.ChargeDO;
import com.central.consume.model.RechargeDetailsVO;
import com.central.consume.service.RechargeService;
import com.central.model.common.PageResult;
import com.central.model.common.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
public class RechargeController {

    @Autowired
    private RechargeService rechargeService;

    @PreAuthorize("hasAuthority('game:get/recharge')")
    @ApiOperation(value = "用户充值记录")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")})
    @GetMapping("/recharge")
    public PageResult<ChargeDO> getRecharge(@RequestParam Map<String, Object> params) {
        params.forEach((k,v)->log.info(k + ":" + v));
        PageResult<ChargeDO> result = rechargeService.listRecharge(params);
        return result;
    }

    @PreAuthorize("hasAuthority('game:get/rechargeDetails')")
    @ApiOperation(value = "充值详情")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")})
    @GetMapping("/rechargeDetails")
    public PageResult<RechargeDetailsVO> getRechargeDetails(@RequestParam Map<String, Object> params) {
        params.forEach((k,v)->log.info(k + ":" + v));
        if (params.containsKey("playerId")){
            if (params.get("playerId") != "-1"){
                params.put("rechargeDetailsSearchKey","player_id");
                params.put("rechargeDetailsSearchValue",params.get("playerId"));
            }
        }
        PageResult<RechargeDetailsVO> result = rechargeService.listRechargeDetails(params);
        return result;
    }

//    @PreAuthorize("hasAuthority('game:get/rechargeDetails')")
//    @ApiOperation(value = "充值详情")
//    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")})
//    @GetMapping("/rechargeById")
//    public PageResult<RechargeDetailsVO> getRechargeDetailsByPlayerId(@RequestParam Map<String, Object> params) {
//        if (params.containsKey("playerId")){
//            return rechargeService.getRechargeDetails(params);
//        }
//        params.forEach((k,v)->log.info(k + ":" + v));
//        return null;
//    }
}
